package com.dshore.messagecenter.controller.warning;

import java.util.List;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dshore.messagecenter.model.basedata.MdApp;
import com.dshore.messagecenter.model.system.ResponseResult;
import com.dshore.messagecenter.model.topicqueue.MdTopic;
import com.dshore.messagecenter.model.warning.MrExceptionMessage;
import com.dshore.messagecenter.service.warning.ExceptionMessageService;
import com.dshore.messagecenter.util.Page;
/**
 * 异常信息控制层
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/exceptionMessage")
public class ExceptionMessageController {
	
	@Autowired
	private ExceptionMessageService exceptionMessageService;
	/**
	 * 页面
	 * @return
	 */
	@RequestMapping(value="/toExceptionMessage")
	public String module() {
		return "warning/mrExceptionMessage";
	}
	
	/**
	 * 获取表格数值
	 * @param exceptionMessage
	 * @return
	 */
	@RequestMapping(value="/getExceptionMessag",method=RequestMethod.POST)
	@ResponseBody
	public Page<MrExceptionMessage> getTemplate(@RequestBody MrExceptionMessage exceptionMessage){
		String str ="^[A-Za-z0-9]+$";
		String str1="^[A-Za-z0-9]+$";
		if((StringUtils.isEmpty(exceptionMessage.getAppCode())||Pattern.compile(str1).matcher(exceptionMessage.getAppCode()).find())&&
				(StringUtils.isEmpty(exceptionMessage.getTopicQueueNo())||Pattern.compile(str).matcher(exceptionMessage.getTopicQueueNo()).find())){
			try{
				return exceptionMessageService.queryListAll(exceptionMessage);
			}catch(Exception e) {
				return null;
			}
		}else {
			return null;
		}
		
	}
	
	/**
	 * 获取主题队列名称
	 * @return
	 */
	@RequestMapping(value="/getTopicName",method=RequestMethod.POST)
	@ResponseBody
	public List<MdTopic> getTopicName(){
		return exceptionMessageService.getTopicName();
		
	}
	
	/**
	 * 获取应用名称下拉
	 * @return
	 */
	@RequestMapping(value="/getAppName",method=RequestMethod.POST)
	@ResponseBody
	public List<MdApp> getAppName(){
		return exceptionMessageService.getAppName();
		
	}
	/**
	 * 删除
	 * @param idArr
	 * @return
	 */
	@RequestMapping(value="/deleteByCodes",method=RequestMethod.POST)
	@ResponseBody
	public ResponseResult<Void> deleteByCodes(String apps,String topics){
		return exceptionMessageService.deleteByCodes(apps,topics);		
	}
	/**
	 * 重发
	 * @param appCode
	 * @param topicQueueNo
	 * @return
	 */
	@RequestMapping(value="/resend",method=RequestMethod.POST)
	@ResponseBody
	public ResponseResult<Void> resend(String appCode,String topicQueueNo){
		return exceptionMessageService.resend(appCode,topicQueueNo);
	}
	
}
